package com.travelparadise.dao;

import java.util.Collection;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.travelparadise.domain.Activite;
import com.travelparadise.domain.Ville;

public class ActiviteDaoHibernate extends HibernateDaoSupport implements ActiviteDao {

	@Override
	public Activite getById(int id) {
		HibernateTemplate hibernateTemplate = this.getHibernateTemplate();
		Activite activite = (Activite) hibernateTemplate.get(com.travelparadise.domain.Activite.class, id);
		return activite;
	}

		
	@Override
	public Collection<Activite> searchByPrice(double min, double max) {
		HibernateTemplate hibernateTemplate = this.getHibernateTemplate();
		String reqHQL = "select activite from Activite as activite " +
							"where activite.prix>="+min+" and activite.prix<="+max;
		return hibernateTemplate.find(reqHQL);
	}



	@Override
	public Collection<Activite> searchByName(String nom) {
		HibernateTemplate hibernateTemplate = this.getHibernateTemplate();
		String searchByNameHql = "select activite from Activite as activite " +
				"where activite.nom like '%"+nom+"%'";
		return hibernateTemplate.find(searchByNameHql);
	}

	@Override
	public Collection<Activite> getActivitesInVille(Ville ville) {
		HibernateTemplate hibernateTemplate = this.getHibernateTemplate();
		Ville laVille = (Ville) hibernateTemplate.get(com.travelparadise.domain.Ville.class, ville.getId());
		return laVille.getActivites();
	}
}